<?php
class Mod_ketquatimkiem extends CI_Controller{
    private $per_page2 = 10;
    private $total_rows2 =100;
    private $tb_phongkham = 'phongkham';
    private $tb_thuoc = 'thuoc';
    private $tb_benh = 'benh';
    private $tb_chuyenkhoa = 'chuyenkhoa';
    private $tb_dinhduong = 'dinhduong';
    private $tb_thongtinbenh = 'thongtinbenh';
    private $trang = 'thongtinbenh';
    function  __construct(){
        parent::__construct();
    }
    function index($dulieu = array()){ // param        
        if(!empty($dulieu)){
            $idbenh = $dulieu['idbenh'];
            $thuoc = $dulieu['thuoc'];
            $dinhduong = $dulieu['dinhduong'];        
            $offset = $dulieu['offset']; //vi tri bat dau lay du lieu   
            $this->trang = $dulieu['trang'];  // trang thuoc, thong tin benh, dinh duong tap luyen            
        }else{
            $thuoc = 1;
            $dinhduong =1;
            $idbenh =0;
            $offset = 0;
        }
        $alias = $this->uri->segment(2,0);
        $alias = $this->security->xss_clean($alias);  
        $alias = preg_replace("/(.html)/", '', $alias);//cat duoi html
        $data['tab_thuoc'] =$thuoc;
        $data['tab_dinhduong'] =$dinhduong;   
        $data['tab_thongtinbenh'] =1;     
        if($idbenh)  {
            $data['tenbenh']= $this->home_model->get_one($this->tb_benh,array('id'=>$idbenh));
        }else $data['tenbenh']= '';
        if($this->trang == 'thongtinbenh'){
            $data['thongtinbenh'] = $this->home_model->get_data($this->tb_thongtinbenh,array('publish'=>1,'idbenh'=>$idbenh),'',$this->per_page2,array('title','alias'),$offset);
            if($alias){
                $data['noidung'] =  $this->home_model->get_one($this->tb_thongtinbenh,array('alias'=>$alias));
                if(empty($data['noidung'])){$data['error']='1';};
            }else $data['noidung'] =  $this->home_model->get_one($this->tb_thongtinbenh,array('idbenh'=>$idbenh));
            $this->total_rows = $this->home_model->get_number($this->tb_thongtinbenh,array('idbenh'=>$idbenh));        
       
        }elseif($this->trang == 'thuoc'){
            $data['thuoc'] = $this->home_model->get_data($this->tb_thuoc,array('publish'=>1,'idbenh'=>$idbenh),'',$this->per_page2,'',$offset);
            if($alias){
                $data['noidung'] =  $this->home_model->get_one($this->tb_thuoc,array('alias'=>$alias));
                if(empty($data['noidung'])){$data['error']='1';};
            }else $data['noidung'] =  $this->home_model->get_one($this->tb_thuoc,array('idbenh'=>$idbenh));
            $this->total_rows = $this->home_model->get_number($this->tb_thuoc,array('idbenh'=>$idbenh));        
       
        }elseif($this->trang=='dinhduong'){
            $data['dinhduong'] = $this->home_model->get_data($this->tb_dinhduong,array('publish'=>1,'idbenh'=>$idbenh),'',$this->per_page2,array('title','alias'),$offset);
            if($alias){
                $data['noidung'] =  $this->home_model->get_one($this->tb_dinhduong,array('alias'=>$alias));
                if(empty($data['noidung'])){$data['error']='1';};
            }else $data['noidung'] =  $this->home_model->get_one($this->tb_dinhduong,array('idbenh'=>$idbenh));
            $this->total_rows = $this->home_model->get_number($this->tb_dinhduong,array('idbenh'=>$idbenh)); 
        }
     
      $this->phantrang2();
       $this->load->view('mod_ketquatimkiem/vmod_'.$this->trang,$data);
    }
    function phantrang2(){
        $this->load->library('pagination');
        $config['base_url'] = 'http://localhost/phongkhamuytin/frontend/index/'.$this->trang;
        $config['total_rows'] = $this->total_rows2;
        $config['per_page'] = $this->per_page2;
        $config['uri_segment'] = 4;
        $config['num_links'] = 12;
     
        $this->pagination->initialize($config);
    
    }
}
?>